package com.wwmz.spring.simple.annotation.configures.imports;

import com.wwmz.spring.simple.project.entity.User;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Created by wumz on 2020/9/27 13:46
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
        boolean company = beanDefinitionRegistry.containsBeanDefinition("com.wwmz.spring.simple.project.entity.Company");
        boolean member = beanDefinitionRegistry.containsBeanDefinition("com.wwmz.spring.simple.project.entity.Member");
        if (company && member){
            BeanDefinition beanDefinition = new RootBeanDefinition(User.class);
            beanDefinitionRegistry.registerBeanDefinition("user", beanDefinition);
        }
    }
}
